import { ElMessageBox } from 'element-plus'
import { ref } from 'vue'

export default function () {
  const whereSelectList = ref<Array<any>>([])
  const logicList = [
    { label: 'AND', value: 'AND' },
    { label: 'OR', value: 'OR' }
  ] as any[]
  const operatorList = [
    { label: '=', value: '=' },
    { label: '!=', value: '!=' },
    { label: '>', value: '>' },
    { label: '<', value: '<' },
    { label: '>=', value: '>=' },
    { label: '<=', value: '<=' },
    { label: 'LIKE', value: 'LIKE' },
    { label: 'IN', value: 'IN' },
    { label: 'BETWEEN', value: 'BETWEEN' },
    { label: 'IS NULL', value: 'IS NULL' },
    { label: 'IS NOT NULL', value: 'IS NOT NULL' }
  ] as any[]

  function addWhereSelect () {
    whereSelectList.value.push({
      field: [],
      logic: 'AND',
      operator: '=',
      valueA: '',
      order: 0,
      valueB: '',
      isParamName: true,
    })
  }

  function deleteWhereSelect (index: number) {
    ElMessageBox.confirm('你确定要删除这条查询条件吗？', '提示', {
      type: 'warning'
    })
      .then(() => {
        whereSelectList.value.splice(index, 1)
      })
      .catch(() => {})
  }

 
  return {
    whereSelectList,
    addWhereSelect,
    deleteWhereSelect,
    logicList,
    operatorList
  }
}
